<?php
namespace Business\Controller;
use Think\Controller;
class IndexController extends BaseController{
//class IndexController extends Controller{
		
	public static $session;		//SESSION
	public static $ordertype;
	protected function _initialize(){
		parent::_initialize();
		
		header("Content-Type: text/html;charset=utf-8");
		$this->assign('tj',time());
		self::$session=$_SESSION['business'];		//session
	
		//p(self::$session);
		self::$ordertype=array('0'=>'派单中','1'=>'待收衣','2'=>'已确认','3'=>'已支付','4'=>'洗涤中','5'=>'待送衣','6'=>'已完成','7'=>'已评论','9'=>'已取消');
		$this->assign('session',self::$session);
		$this->assign('ordertype',self::$ordertype);
	}

    public function index(){
		$this->display();
    }
	
	//订单列表
	 public function orderlist(){
	 	if(IS_POST){
			$p=I('post.');
			//p($p);
			$map['shopid']=self::$session['shop']['shopid'];
			//==============
			if($p['addtime'] && $p['endtime']){
				$map['addstamp'] = array('between', strtotime($p['addtime']).','.strtotime($p['endtime']));
			}
			if($p['status']!='-1'){
				$map['status'] = $p['status'];
			}
			if($p['orderid']){
				$map['orderid'] = $p['orderid'];
				$map['_logic'] = 'OR';
			}
			if($p['name']){
				$name=$p['name'];
				$map['name'] = array('like',"%$name%");
				$map['_logic'] = 'OR';
			}
			if($p['phone']){
				$phone=$p['phone'];
				$map['phone'] = array('like',"%$phone%");
				$map['_logic'] = 'OR';
			}
		}
		if(I('where')){
			$map['addtime']=array('like',date('Y-m-d',time()).'%');
		}
		
		$map['shopid']=self::$session['shop']['shopid'];
		$shoplist=M('bb_order')->where($map)->select();
		//echo M('bb_order')->getLastSql();
		$this->assign('shoplist',$shoplist);
		$this->display();
    }
	//订单查询
	public function ordersearch(){
		$this->display();
	}
	//订单详情
	public function orderinfo(){
		$orderid=I('orderid');
		if($orderid){
			$orderinfo=M('bb_order')->where(array('orderid'=>$orderid))->find();
			$this->assign('shopinfo',$orderinfo);
			$this->display();
		}
	}
	//会员列表
	public function userlist(){
		$user=M('bb_shop_user')->where(array('shopid'=>self::$session['shop']['shopid']))->select();
		foreach ($user as $k => $v) {
			$user[$k]['user']=M('weixin_client_user')->table('weixin_client_user wu')->join('client_user N on wu.openid=N.openid')->field('wu.headimgurl,N.name,N.phone')->where(array('wu.openid'=>$v['user_openid']))->find();
		}
		$this->assign('userlist',$user);
		//p($user);
		$this->display();
	}
	
	//===============
	//阿姨管理
	public function auntie(){
		$auntie=M('bb_auntie')->where(array('shopid'=>self::$session['shop']['shopid']))->select();
		foreach ($auntie as $k => $v) {
			$au=M('weixin_auntie_user')->field('headimgurl')->where(array('openid'=>$v['openid']))->find();
			$auntie[$k]['tximg']=$au['headimgurl'];
		}
		$this->assign('auntie',$auntie);
		$this->display();
		
	}
	
	//添加阿姨
	public function addauntie(){
		$options['appid']=C('BB_APPID_auntie');
		$options['secret']=C('BB_SECRET_auntie');
		$wx=new \bb\Wechat($options);
		$re=$wx->getQRUrl($_SESSION['business']['shop']['id']);
		$this->assign('getimg',$re);
		$this->display();
	}
	
	public function rules(){
		$this->display();
	}
	//店铺2维码
	public function qrcode(){
		$options['appid']=C('BB_APPID_client');
		$options['secret']=C('BB_SECRET_client');
		$wx=new \bb\Wechat($options);
		$re=$wx->getQRUrl_str('shop_'.$_SESSION['business']['shop']['id']);
		$this->assign('getimg',$re);
		$this->display();
	}
	
}